using Mahjong.Code;
using MahjongAIR.Avalon.Images;
using ScriptCoreLib.Extensions;
using ScriptCoreLib.Shared.Avalon.Extensions;
using System;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
using System.Xml;
using System.Xml.Linq;

namespace MahjongAIR
{
    public class ApplicationCanvas : Canvas
    {
        public int DefaultWidth = MahjongGameControl.DefaultWidth;
        public int DefaultHeight = MahjongGameControl.DefaultHeight;

        public Mahjong.Code.MahjongGameControl g;


        icon48 __preview = new icon48();

        public ApplicationCanvas()
        {
            this.Background = Brushes.Black;


            #region background
            var __bg = new Image
            {
                Source = "assets/Mahjong.Assets/china.jpg".ToSource(),
                Stretch = System.Windows.Media.Stretch.Fill,
            }.AttachTo(this);

            var __bgshadow = new Image
            {
                Source = "assets/Mahjong.Assets/shadow.png".ToSource(),
                Stretch = System.Windows.Media.Stretch.Fill,
            }.AttachTo(this);
            #endregion

            Action AtSizeChanged = delegate
            {
                __bg.SizeTo(
                 this.Width,
                  this.Height
             );

                __bgshadow.SizeTo(
                   this.Width,
                    this.Height
               );
            };


            this.SizeChanged +=
                delegate
                {
                    AtSizeChanged();

                };

            AtSizeChanged();

            g = new Mahjong.Code.MahjongGameControl(NoBackground: true);

            g.AttachTo(this);

            g.DiagnosticsContainer.Visibility = System.Windows.Visibility.Hidden;

            // less features!
            g.Navbar.Container.Orphanize();

            this.SizeChanged +=
                delegate
                {
                    g.MoveTo(
                        (this.Width - g.Width) / 2,
                        0
                    );
                };

        }

    }
}
